package com.qhy.springcloud.service;


import com.qhy.springcloud.api.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author qiuhongyu
 * @date 2020/11/13 11:55
 */
@Service
public class DeptService {
    private static final String HOST_URL_PREXY = "http://springcloud-nacos-provider";

    @Autowired
    private RestTemplate restTemplatel;

    @Value("${server.port}")
    private String serverPort;

    public boolean addDept(Dept dept) {

        return false;
    }


    public Dept queryDept(Long id) {
        String url = HOST_URL_PREXY + "/queryDept/" + id;
        Dept dept = restTemplatel.getForObject(url, Dept.class);

        return dept;
    }

    public List<Dept> queryDepts() {
        return null;
    }


    public String getPort() {
        //  private static final String HOST_URL_PREXY = "http://springcloud-nacos-provider";
        String url = HOST_URL_PREXY + "/serverPort";
        return restTemplatel.getForObject(url, String.class);
    }


}
